package com.sheng.leetcode.year2022.month09.day27;

import org.junit.Test;

import java.util.Arrays;

/**
 * @author liusheng
 * @date 2022/09/27
 *<p>
 * 面试题 01.02. 判定是否互为字符重排<p>
 *<p>
 * 给定两个字符串 s1 和 s2，请编写一个程序，<p>
 * 确定其中一个字符串的字符重新排列后，能否变成另一个字符串。<p>
 *<p>
 * 示例 1：<p>
 * 输入: s1 = "abc", s2 = "bca"<p>
 * 输出: true <p>
 *<p>
 * 示例 2：<p>
 * 输入: s1 = "abc", s2 = "bad"<p>
 * 输出: false<p>
 * 说明：<p>
 *<p>
 * 0 <= len(s1) <= 100<p>
 * 0 <= len(s2) <= 100<p>
 *<p>
 * 来源：力扣（LeetCode）<p>
 * 链接：<a href="https://leetcode.cn/problems/check-permutation-lcci">...</a><p>
 * 著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。<p>
 */
public class LeetCodeCheckPermutation {

    @Test
    public void test01() {
//        String s1 = "abc", s2 = "bca";
        String s1 = "abc", s2 = "bad";
        System.out.println(new Solution().CheckPermutation(s1, s2));
    }
}
class Solution {
    public boolean CheckPermutation(String s1, String s2) {
        if (s1.length() != s2.length()) {
            return false;
        }
        char[] c1 = s1.toCharArray();
        char[] c2 = s2.toCharArray();
        Arrays.sort(c1);
        Arrays.sort(c2);
        return new String(c1).equals(new String(c2));
    }
}
